#pragma once
#include <vector>

namespace Physics
{
	class Body;
	class CollisionSystem;
	class Primitive;
	class CollisionSkin;
	typedef std::vector<Primitive*> PrimitiveVector;

	class CollisionSkin
	{

	public:
		CollisionSkin(Body* owner);
		~CollisionSkin();
		
		CollisionSystem* getCollisionSystem() { return mCollisionSystem; }
		void setCollisionSystem(CollisionSystem* v) { mCollisionSystem = v; }

		Body* getOwner() { return mOwner; }
		void setOwner(Body* v) { mOwner = v; }

		const AxisAlignedBox& getWorldBoundingBox() const { return mWorldBoundingBox; }

		int AddPrimitive(const Primitive &prim);
		void RemoveAllPrimitives();
		size_t GetNumPrimitives() const {return mPrimitives.size();}

		const Primitive* GetPrimitive(size_t iPrim) const {return mPrimitives[iPrim];}

		void UpdateWorldBoundingBox();

		void ApplyTransform(const Transform3& trans);
		
		bool SegmentIntersect(
			float & frac, 
			Vector3 & pos, 
			Vector3 & normal, 
			const struct Segment & seg) const;
		
		bool SphereIntersect(
			float & frac, 
			Vector3 & pos, 
			Vector3 & normal, 
			const struct Segment & seg,
			float radius) const;

	private:
		Body* mOwner;
		AxisAlignedBox mWorldBoundingBox;
		CollisionSystem* mCollisionSystem;
		Transform3 mTransform;
		PrimitiveVector mPrimitives;
	};
};
